package com.oim.core.common.box;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.oim.core.bean.GroupMember;

/**
 * 描述：这里是用于存放个人信息的集合
 * 
 * @author XiaHui
 * @date 2016年1月15日 下午7:15:17
 * @version 0.0.1
 */
public class PersonalBox {
	
	private static Map<Object, Object> objectMap = new ConcurrentHashMap<Object, Object>();
	private static Map<String, GroupMember> groupMemberMap = new ConcurrentHashMap<String,GroupMember>();

	public static void put(Object key, Object value) {
		objectMap.put(key, value);
	}

	@SuppressWarnings("unchecked")
	public static <T> T get(Object key) {
		return (T) objectMap.get(key);
	}
	
	
	public static void put( List<GroupMember> list) {
		if(null!=list){
			for(GroupMember gm:list){
				groupMemberMap.put(gm.getGroupId(), gm);
			}
		}
	}
	public static String getGroupPosition(String groupId) {
		String position = "3";
		GroupMember gm = groupMemberMap.get(groupId);
		if (null != gm) {
			position = gm.getPosition();
		}
		return position;
	}
	
	public static boolean isOwner(String groupId) {
		String position = getGroupPosition(groupId);
		boolean mark = GroupMember.position_owner.equals(position);
		return mark;
	}

	public static boolean isNormal(String groupId) {
		String position = getGroupPosition(groupId);
		boolean mark = !GroupMember.position_owner.equals(position) && !GroupMember.position_admin.equals(position);
		return mark;
	}

	public static boolean isAdmin(String groupId) {
		String position = getGroupPosition(groupId);
		boolean mark = GroupMember.position_admin.equals(position);
		return mark;
	}
}
